<?php

require '../vendor/autoload.php';

use PhpParser\Error;
use PhpParser\ParserFactory;
use PhpParser\NodeDumper;

// 要解析的 PHP 代码
$code = '<?php
$a = \'test\';
$b = "test";
class test{
    public $instruction = [
        "a" => "b",
        "b" => "b",
        "c" => "b",
    ];
    public function test(){
        $Message.= $a["b"]["c"]["d"];
    }
}';

echo $code;

// 创建一个解析器实例
$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);

try {
    // 解析代码生成 AST
    $ast = $parser->parse($code);
    print_r($ast);

    // 使用 NodeDumper 输出 AST
    //$dumper = new NodeDumper();
    //echo $dumper->dump($ast, true);
} catch (Error $error) {
    echo "Parse Error: ", $error->getMessage();
}
?>

